package com.xiaoyi.query;

import com.xiaoyi.analyzer.*;
import com.xiaoyi.enums.DataBaseTypeEnum;
import com.xiaoyi.enums.ResultTypeAggEnum;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author xiaoyi
 * @version 1.0.0
 * @createTime 2023-02-21 23:32:00
 */
public class QueryFactory {
    static Map<DataBaseTypeEnum,Class> queryMap = new HashMap<>();
    static {
        queryMap.put(DataBaseTypeEnum.MYSQL, MysqlQuery.class);
    }
    public static Query createQuery(DataBaseTypeEnum aggEnum){
        Class aClass = queryMap.get(aggEnum);
        if (Objects.isNull(aClass)){
            return null;
        }
        try {
            return (Query) aClass.getConstructor().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return null;
    }
}
